package org.rslai.tcedit.business.impl;

import java.util.List;
import java.util.Set;
import org.rslai.tcedit.business.UserService;
import org.rslai.tcedit.domain.Page;
import org.rslai.tcedit.domain.Role;
import org.rslai.tcedit.domain.User;
import org.rslai.tcedit.domain.UserDetails;
import org.rslai.tcedit.security.SecurityUtil;

/**
 * UserService 接口的实现<br/>
 * 注意: <tx:annotation-driven /> 这些方法已支持事务
 * 
 * @author rslai
 * 
 * @spring.bean id="userService"
 */
public class UserServiceImpl extends AbstractBaseService implements UserService {

	public void create(User user, UserDetails userDetails, Set<Role> roles) {
		user.setUserDetails(userDetails);
		user.setRoles(roles);
		userDao.create(user);
	}

	public void update(User user, UserDetails userDetails, Set<Role> roles) {
		user.setUserDetails(userDetails);
		user.setRoles(roles);
		userDao.update(user);
	}

	public List<User> query(boolean asc) {
		return userDao.query(asc);
	}

	public List<User> query(Page page, String username, String realName, String email, boolean asc) {
		return userDao.query(page, username, realName, email, asc);
	}

	public User query(String username) {
		return userDao.queryUser(username);
	}

	public void changePassword(String username, String oldPassword, String newPassword) {
		SecurityUtil.assertUsername(username);
		userDao.changePassword(username, oldPassword, newPassword);
	}

}
